package com.joizhang.reactor.app;

import com.joizhang.reactor.framework.*;

import java.io.IOException;

/**
 * @author joizhang
 */
public class LoggingServer {

    public static void main(String[] args) throws IOException {
        Dispatcher dispatcher = new ThreadPoolDispatcher(2);
        NioReactor reactor = new NioReactor(dispatcher);
        LoggingServerHandler loggingServerHandler = new LoggingServerHandler();
        reactor.registerChannel(tcpChannel(6666, loggingServerHandler)).start();
    }

    private static AbstractNioChannel tcpChannel(int port, ChannelHandler handler) throws IOException {
        NioServerSocketChannel channel = new NioServerSocketChannel(port, handler);
        channel.bind();
        return channel;
    }

}
